﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhittleList.Bll;
using System.Data.Linq;
using WhittleList.Tests.Helpers;

namespace WhittleList.Tests.Mocks
{
    public class FakeProject : Moq.Mock<Project>
    {
        public static List<FakeProject> GetList(int number)
        {
            return GetList(number, new Random());
        }

        public static List<FakeProject> GetList(int number, Random rnd)
        {
            var tmp = new List<FakeProject>();
            while (tmp.Count < number)
            {
                var i = tmp.Count + 1;

                tmp.Add(new FakeProject(i, string.Format("Project {0}", i), string.Format("Summary {0}", i), MockHelpers.CreateBinary(rnd)));
            }
            return tmp;
        }

        public FakeProject(int id, string name, string summary, System.Data.Linq.Binary cid)
        {
            this.Setup(x => x.Id).Returns(id);
            this.SetupProperty(x => x.Name, name);
            this.SetupProperty(x => x.Summary, summary);
            this.Setup(x => x.CID).Returns(cid);
        }

        internal void SetSite(FakeSite site)
        {
            this.Setup(x => x.SiteId).Returns(site.Object.Id);
            this.Setup(x => x.Site).Returns(site.Object);
        }

        internal void SetSections(List<FakeSection> sections)
        {
            var tmp = new EntitySet<Section>();
            tmp.Assign(sections.Convert());
            Setup(x => x.Sections).Returns(tmp);

            sections.ForEach(x => x.SetProject(this));
        }
    }
}
